ddaefff2c31f726a342f706f156bbeed86eb6c40,src/main/java/com/github/games647/lagmonitor/storage/MonitorSaveTask.java,MonitorSaveTask,getWorldData,#,89

Before Change


            throws ExecutionException, InterruptedException {
        //this is not thread-safe and have to run sync
        Future<Map<UUID, WorldData>> worldFuture = Bukkit.getScheduler()
                .callSyncMethod(plugin, new Callable<Map<UUID, WorldData>>() {
                    @Override
                    public Map<UUID, WorldData> call() throws Exception {
                        List<World> worlds = Bukkit.getWorlds();
                        Map<UUID, WorldData> worldsData = Maps.newHashMapWithExpectedSize(worlds.size());
                        for (World world : worlds) {
                            UUID worldId = world.getUID();
                            String worldName = world.getName();
                            int tileEntities = 0;
                            for (Chunk loadedChunk : world.getLoadedChunks()) {
                                tileEntities += loadedChunk.getTileEntities().length;
                            }

                            int entities = world.getEntities().size();
                            int chunks = world.getLoadedChunks().length;

                            WorldData worldData = new WorldData(worldName, chunks, tileEntities, entities);
                            worldsData.put(worldId, worldData);
                        }

                        return worldsData;
                    }
                });

        Map<UUID, WorldData> worldsData = worldFuture.get();
        //this can run async because it's thread-safe

After Change


            throws ExecutionException, InterruptedException {
        //this is not thread-safe and have to run sync
        Future<Map<UUID, WorldData>> worldFuture = Bukkit.getScheduler()
                .callSyncMethod(plugin, () -> {
                    List<World> worlds = Bukkit.getWorlds();
                    Map<UUID, WorldData> worldsData = Maps.newHashMapWithExpectedSize(worlds.size());
                    for (World world : worlds) {
                        UUID worldId = world.getUID();
                        String worldName = world.getName();
                        int tileEntities = 0;
                        for (Chunk loadedChunk : world.getLoadedChunks()) {
                            tileEntities += loadedChunk.getTileEntities().length;
                        }

                        int entities = world.getEntities().size();
                        int chunks = world.getLoadedChunks().length;

                        WorldData worldData = new WorldData(worldName, chunks, tileEntities, entities);
                        worldsData.put(worldId, worldData);
                    }

                    return worldsData;
                });

        Map<UUID, WorldData> worldsData = worldFuture.get();
        //this can run async because it's thread-safe